package com.cy.cy2025.activity

import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.cy.cy2025.R


/**
 * 左边文本框优先换行的例子
 */
class LeftTextFirstLineActivity : AppCompatActivity() {



    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_left_text_first_line)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }



        findViewById<TextView>(R.id.tv_cp).text =
            """
                如果是用的compose，可以这样实现：（关键点在于左边的视图使用width = Dimension.preferredWrapContent）
                @Preview
                @Composable
                fun AdaptiveTextLayout() {
                    ConstraintLayout {
                        val (t1,t2) = createRefs()
            
                        Text(
                            text = "个1231111111111111个",
                            modifier = Modifier
                                .constrainAs(t2) {
                                    top.linkTo(parent.top)
                                    end.linkTo(parent.end)
                                }
                                .background(Color(0xFF2d2d2d)),
                            color = Color.White
                        )
            
                        Text(
                            text = "aaaaaaa啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊",
                            maxLines = Int.MAX_VALUE,
                            modifier = Modifier
                                .constrainAs(t1) {
                                    top.linkTo(t2.top)
                                    start.linkTo(parent.start)
                                    end.linkTo(t2.start)
                                    width = Dimension.preferredWrapContent
                                }
                                .background(Color(0xFF7777dd)),
            
                            color = Color.White
                        )
                    }
                }
            """.trimIndent()
    }
}